package com.juicygames.framework.draw;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.juicygames.framework.draw.drawservice.DrawHandler;
import com.juicygames.framework.draw.drawservice.Drawable;
import com.juicygames.framework.gamepart.GameHandler;
import com.juicygames.framework.gamepart.GamePart;

public class DrawService extends GamePart {
	
	private List<Drawable> drawables;

	public DrawService(GamePart parent) {
		super(parent);
		addHandler(new DrawHandler(this));
		drawables = new ArrayList<Drawable>();
	}

	public <G extends GameHandler> void register(G handler) {
		Drawable drawable = new Drawable();
		drawable.entity = handler.getSelf();
		drawable.depth = handler.getSelf().getPart(DrawDepth.class);
		drawable.drawHandler = handler;
		
		drawables.add(drawable);
		Collections.sort(drawables);
	}
	
	public List<Drawable> getDrawables() {
		return drawables;
	}

}
